<template>
  <div class="profile-page">
    <el-row :gutter="24">
      <!-- 个人信息卡片 -->
      <el-col :xs="24" :lg="8">
        <el-card class="profile-card" shadow="hover">
          <template #header>
            <div class="card-header">
              <div class="header-left">
                <el-icon class="header-icon"><User /></el-icon>
                <span class="header-title">个人信息</span>
              </div>
              <el-button type="primary" size="small" @click="editProfile" :icon="Edit">
                编辑资料
              </el-button>
            </div>
          </template>
          
          <div class="profile-info">
            <div class="avatar-section">
              <div class="avatar-container">
                <el-avatar :size="100" :src="userInfo.avatar" class="user-avatar">
                  <el-icon size="40"><User /></el-icon>
                </el-avatar>
                <div class="avatar-overlay">
                  <el-upload
                    class="avatar-uploader"
                    :show-file-list="false"
                    :before-upload="handleAvatarUpload"
                    accept="image/*"
                  >
                    <el-icon class="upload-icon"><Camera /></el-icon>
                  </el-upload>
                </div>
              </div>
              <p class="upload-tip">点击相机图标更换头像</p>
            </div>
            
            <div class="user-details">
              <h3 class="user-name">{{ userInfo.nickName || userInfo.userName }}</h3>
              <div class="user-badges">
                <el-tag
                  v-for="role in userInfo.roleNames"
                  :key="role"
                  type="primary"
                  size="small"
                  class="role-tag"
                >
                  {{ role }}
                </el-tag>
              </div>
              <p class="user-dept">
                <el-icon><OfficeBuilding /></el-icon>
                {{ userInfo.deptName || '未分配部门' }}
              </p>
            </div>
          </div>
          
          <div class="profile-stats">
            <div class="stats-grid">
              <div class="stat-item">
                <div class="stat-icon">
                  <el-icon><Clock /></el-icon>
                </div>
                <div class="stat-content">
                  <span class="stat-label">登录次数</span>
                  <span class="stat-value">{{ userInfo.loginCount || 0 }}</span>
                </div>
              </div>
              <div class="stat-item">
                <div class="stat-icon">
                  <el-icon><Calendar /></el-icon>
                </div>
                <div class="stat-content">
                  <span class="stat-label">最后登录</span>
                  <span class="stat-value">{{ formatDate(userInfo.lastLoginTime) }}</span>
                </div>
              </div>
            </div>
          </div>
        </el-card>
      </el-col>
      
      <!-- 详细信息 -->
      <el-col :xs="24" :lg="16">
        <el-card class="detail-card" shadow="hover">
          <template #header>
            <div class="card-header">
              <div class="header-left">
                <el-icon class="header-icon"><Setting /></el-icon>
                <span class="header-title">账户设置</span>
              </div>
              <el-button 
                type="primary" 
                :icon="ArrowLeft" 
                @click="goBack"
                class="back-button"
                size="small"
              >
                首页
              </el-button>
            </div>
          </template>
          
          <el-tabs v-model="activeTab" class="profile-tabs">
            <el-tab-pane label="基本信息" name="basic">
              <div class="tab-content">
                <el-form :model="profileForm" label-width="120px" class="profile-form">
                  <div class="basic-info-section">
                    <h4 class="section-title">基本信息</h4>
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="用户名">
                          <el-input v-model="profileForm.userName" disabled>
                            <template #prefix>
                              <el-icon><User /></el-icon>
                            </template>
                          </el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="昵称">
                          <el-input v-model="profileForm.nickName">
                            <template #prefix>
                              <el-icon><Edit /></el-icon>
                            </template>
                          </el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="邮箱">
                          <el-input v-model="profileForm.email">
                            <template #prefix>
                              <el-icon><Message /></el-icon>
                            </template>
                          </el-input>
                        </el-form-item>
                      </el-col>
                      <el-col :span="12">
                        <el-form-item label="手机号">
                          <el-input v-model="profileForm.phoneNumber">
                            <template #prefix>
                              <el-icon><Phone /></el-icon>
                            </template>
                          </el-input>
                        </el-form-item>
                      </el-col>
                    </el-row>
                    <el-row :gutter="20">
                      <el-col :span="12">
                        <el-form-item label="性别">
                          <el-select v-model="profileForm.sex" style="width: 100%">
                            <el-option label="男" value="0" />
                            <el-option label="女" value="1" />
                            <el-option label="未知" value="2" />
                          </el-select>
                        </el-form-item>
                      </el-col>
                    </el-row>
                  </div>
                  
                  <div class="organization-info-section">
                    <h4 class="section-title">组织信息</h4>
                    <el-form-item label="部门">
                      <el-input v-model="userInfo.deptName" disabled>
                        <template #prefix>
                          <el-icon><OfficeBuilding /></el-icon>
                        </template>
                      </el-input>
                    </el-form-item>
                    <el-form-item label="角色">
                      <div class="role-tags">
                        <el-tag
                          v-for="role in userInfo.roleNames"
                          :key="role"
                          type="info"
                          size="large"
                          class="role-tag-large"
                        >
                          {{ role }}
                        </el-tag>
                      </div>
                    </el-form-item>
                    <el-form-item label="创建时间">
                      <el-input v-model="userInfo.createTime" disabled>
                        <template #prefix>
                          <el-icon><Calendar /></el-icon>
                        </template>
                      </el-input>
                    </el-form-item>
                    <el-form-item label="最后登录IP">
                      <el-input :value="userInfo.lastLoginIp || '未知'" disabled>
                        <template #prefix>
                          <el-icon><Location /></el-icon>
                        </template>
                      </el-input>
                    </el-form-item>
                    <el-form-item label="账户类型">
                      <el-tag :type="userInfo.userType === 'admin' ? 'danger' : 'primary'" size="large">
                        <el-icon><User /></el-icon>
                        {{ userInfo.userType === 'admin' ? '管理员' : '普通用户' }}
                      </el-tag>
                    </el-form-item>
                  </div>
                  
                  <div class="form-actions">
                    <el-button type="primary" @click="saveProfile" :loading="saving">
                      <el-icon><Check /></el-icon>
                      保存修改
                    </el-button>
                    <el-button @click="resetProfile">
                      <el-icon><Refresh /></el-icon>
                      重置
                    </el-button>
                  </div>
                </el-form>
              </div>
            </el-tab-pane>
            
            <el-tab-pane label="安全设置" name="password">
              <div class="tab-content">
                <div class="security-section">
                  <h4 class="section-title">账户安全状态</h4>
                  <div class="security-status">
                    <div class="security-item">
                      <div class="security-label">
                        <el-icon><Lock /></el-icon>
                        密码强度
                      </div>
                      <div class="security-value">
                        <el-tag type="success" size="small">{{ securityInfo.passwordStrength }}</el-tag>
                        <span class="security-desc">密码包含大小写字母、数字和特殊字符</span>
                      </div>
                    </div>
                    <div class="security-item">
                      <div class="security-label">
                        <el-icon><Calendar /></el-icon>
                        密码更新时间
                      </div>
                      <div class="security-value">
                        <span class="security-text">{{ securityInfo.passwordUpdateTime }}</span>
                        <span class="security-desc">距离上次更新已过去 {{ getDaysSinceUpdate() }} 天</span>
                      </div>
                    </div>
                    <div class="security-item">
                      <div class="security-label">
                        <el-icon><Location /></el-icon>
                        常用登录地点
                      </div>
                      <div class="security-value">
                        <span class="security-text">{{ securityInfo.commonLoginLocation }} ({{ securityInfo.loginCount }}次)</span>
                        <span class="security-desc">最近7天内的登录记录</span>
                      </div>
                    </div>
                  </div>
                  
                  <h4 class="section-title">修改密码</h4>
                  <p class="section-desc">定期修改密码可以提高账户安全性</p>
                  
                  <el-form
                    ref="passwordFormRef"
                    :model="passwordForm"
                    :rules="passwordRules"
                    label-width="120px"
                    class="password-form"
                  >
                    <el-form-item label="原密码" prop="oldPassword">
                      <el-input
                        v-model="passwordForm.oldPassword"
                        type="password"
                        show-password
                        placeholder="请输入原密码"
                        size="large"
                      >
                        <template #prefix>
                          <el-icon><Lock /></el-icon>
                        </template>
                      </el-input>
                    </el-form-item>
                    <el-form-item label="新密码" prop="newPassword">
                      <el-input
                        v-model="passwordForm.newPassword"
                        type="password"
                        show-password
                        placeholder="请输入新密码"
                        size="large"
                      >
                        <template #prefix>
                          <el-icon><Lock /></el-icon>
                        </template>
                      </el-input>
                    </el-form-item>
                    <el-form-item label="确认密码" prop="confirmPassword">
                      <el-input
                        v-model="passwordForm.confirmPassword"
                        type="password"
                        show-password
                        placeholder="请再次输入新密码"
                        size="large"
                      >
                        <template #prefix>
                          <el-icon><Lock /></el-icon>
                        </template>
                      </el-input>
                    </el-form-item>
                    <el-form-item>
                      <div class="password-actions">
                        <el-button type="primary" @click="handlePasswordChange" :loading="changingPassword">
                          <el-icon><Check /></el-icon>
                          修改密码
                        </el-button>
                        <el-button @click="resetPasswordForm">
                          <el-icon><Refresh /></el-icon>
                          重置
                        </el-button>
                      </div>
                    </el-form-item>
                  </el-form>
                </div>
              </div>
            </el-tab-pane>
            
            <el-tab-pane label="登录记录" name="logs">
              <div class="tab-content">
                <div class="login-logs-section">
                  <h4 class="section-title">最近登录记录</h4>
                  <p class="section-desc">查看您的账户登录历史和安全状态</p>
                  
                  <!-- 登录统计信息 -->
                  <div class="login-stats">
                    <div class="stat-card">
                      <div class="stat-icon">
                        <el-icon><Clock /></el-icon>
                      </div>
                      <div class="stat-content">
                        <div class="stat-number">{{ loginLogs.length }}</div>
                        <div class="stat-label">最近登录次数</div>
                      </div>
                    </div>
                    <div class="stat-card">
                      <div class="stat-icon">
                        <el-icon><Location /></el-icon>
                      </div>
                      <div class="stat-content">
                        <div class="stat-number">{{ getUniqueLocations() }}</div>
                        <div class="stat-label">登录地点数</div>
                      </div>
                    </div>
                    <div class="stat-card">
                      <div class="stat-icon">
                        <el-icon><Calendar /></el-icon>
                      </div>
                      <div class="stat-content">
                        <div class="stat-number">{{ getLastLoginDays() }}</div>
                        <div class="stat-label">距上次登录(天)</div>
                      </div>
                    </div>
                  </div>
                  
                  <el-table :data="loginLogs" style="width: 100%" class="login-logs-table" :show-overflow-tooltip="false">
                    <el-table-column prop="loginTime" label="登录时间" min-width="200" show-overflow-tooltip>
                      <template #default="{ row }">
                        <div class="time-cell">
                          <el-icon><Clock /></el-icon>
                          <span class="cell-text">{{ row.loginTime }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column prop="ipAddress" label="IP地址" min-width="140" show-overflow-tooltip>
                      <template #default="{ row }">
                        <div class="ip-cell">
                          <el-icon><Location /></el-icon>
                          <span class="cell-text">{{ row.ipAddress }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column prop="location" label="登录地点" min-width="160" show-overflow-tooltip>
                      <template #default="{ row }">
                        <div class="location-cell">
                          <el-icon><MapLocation /></el-icon>
                          <span class="cell-text">{{ row.location }}</span>
                        </div>
                      </template>
                    </el-table-column>
                    <el-table-column prop="browser" label="浏览器" min-width="120" show-overflow-tooltip>
                      <template #default="{ row }">
                        <el-tag size="small" type="info" class="browser-tag">{{ row.browser }}</el-tag>
                      </template>
                    </el-table-column>
                    <el-table-column prop="os" label="操作系统" min-width="140" show-overflow-tooltip>
                      <template #default="{ row }">
                        <el-tag size="small" type="warning" class="os-tag">{{ row.os }}</el-tag>
                      </template>
                    </el-table-column>
                    <el-table-column prop="status" label="状态" min-width="100" show-overflow-tooltip>
                      <template #default="{ row }">
                        <el-tag :type="row.status === '成功' ? 'success' : 'danger'" size="small" class="status-tag">
                          <el-icon><CircleCheck v-if="row.status === '成功'" /><CircleClose v-else /></el-icon>
                          {{ row.status }}
                        </el-tag>
                      </template>
                    </el-table-column>
                  </el-table>
                </div>
              </div>
            </el-tab-pane>
          </el-tabs>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script setup lang="ts">
import { ref, reactive, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import { ElMessage, type FormInstance, type FormRules } from 'element-plus'
import { 
  User, 
  Edit, 
  Camera, 
  OfficeBuilding, 
  Clock, 
  Calendar, 
  Setting, 
  Message, 
  Phone, 
  Lock, 
  Check, 
  Refresh, 
  Location, 
  MapLocation,
  ArrowLeft
} from '@element-plus/icons-vue'
import { useUserStore } from '@/stores/user'
import { changePasswordApi, uploadAvatarApi } from '@/api/user'
import type { ProfileForm, PasswordForm } from '@/types/user'

const userStore = useUserStore()
const router = useRouter()
const activeTab = ref('basic')
const passwordFormRef = ref<FormInstance>()
const saving = ref(false)
const changingPassword = ref(false)

// 安全状态信息
const securityInfo = ref({
  passwordStrength: '强',
  passwordUpdateTime: '2024-01-15 14:30:00',
  commonLoginLocation: '北京市',
  loginCount: 3
})

// 用户信息
const userInfo = ref({
  userId: 1,
  userName: 'admin',
  nickName: '管理员',
  email: 'admin@convallaria.com',
  phoneNumber: '13800138000',
  sex: '0',
  status: '0',
  avatar: '',
  deptName: '技术部',
  roleNames: ['管理员', '系统管理员'],
  createTime: '2024-01-01 00:00:00',
  lastLoginTime: '2024-01-27 10:30:00',
  lastLoginIp: '192.168.1.100',
  loginCount: 156,
  userType: 'admin'
})

// 个人资料表单
const profileForm = reactive<ProfileForm>({
  nickName: '',
  email: '',
  phoneNumber: '',
  sex: '0',
  avatar: ''
})

// 密码修改表单
const passwordForm = reactive<PasswordForm>({
  oldPassword: '',
  newPassword: '',
  confirmPassword: ''
})

// 密码验证规则
const passwordRules: FormRules = {
  oldPassword: [
    { required: true, message: '请输入原密码', trigger: 'blur' }
  ],
  newPassword: [
    { required: true, message: '请输入新密码', trigger: 'blur' },
    { min: 6, max: 20, message: '密码长度在 6 到 20 个字符', trigger: 'blur' },
    {
      pattern: /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[a-zA-Z\d@$!%*?&]{6,}$/,
      message: '密码必须包含大小写字母和数字',
      trigger: 'blur'
    }
  ],
  confirmPassword: [
    { required: true, message: '请确认新密码', trigger: 'blur' },
    {
      validator: (rule, value, callback) => {
        if (value !== passwordForm.newPassword) {
          callback(new Error('两次输入密码不一致'))
        } else {
          callback()
        }
      },
      trigger: 'blur'
    }
  ]
}

// 登录日志
const loginLogs = ref([
  {
    loginTime: '2024-01-27 10:30:00',
    ipAddress: '192.168.1.100',
    location: '北京市',
    browser: 'Chrome',
    os: 'Windows 10',
    status: '成功'
  },
  {
    loginTime: '2024-01-26 15:20:00',
    ipAddress: '192.168.1.101',
    location: '北京市',
    browser: 'Firefox',
    os: 'Windows 10',
    status: '成功'
  },
  {
    loginTime: '2024-01-25 09:15:00',
    ipAddress: '192.168.1.102',
    location: '上海市',
    browser: 'Safari',
    os: 'macOS',
    status: '成功'
  }
])

// 返回首页
const goBack = () => {
  router.push('/dashboard')
}

// 编辑个人资料
const editProfile = () => {
  Object.assign(profileForm, {
    nickName: userInfo.value.nickName,
    email: userInfo.value.email,
    phoneNumber: userInfo.value.phoneNumber,
    sex: userInfo.value.sex,
    avatar: userInfo.value.avatar
  })
  activeTab.value = 'basic'
}

// 保存个人资料
const saveProfile = async () => {
  try {
    saving.value = true
    // 这里应该调用保存个人资料的API
    // await updateProfileApi(profileForm)
    
    // 更新用户信息
    Object.assign(userInfo.value, profileForm)
    ElMessage.success('个人资料保存成功')
  } catch (error) {
    ElMessage.error('保存失败，请重试')
  } finally {
    saving.value = false
  }
}

// 重置个人资料
const resetProfile = () => {
  Object.assign(profileForm, {
    nickName: userInfo.value.nickName,
    email: userInfo.value.email,
    phoneNumber: userInfo.value.phoneNumber,
    sex: userInfo.value.sex,
    avatar: userInfo.value.avatar
  })
  ElMessage.info('已重置为原始数据')
}

// 修改密码
const handlePasswordChange = async () => {
  if (!passwordFormRef.value) return
  
  try {
    changingPassword.value = true
    await passwordFormRef.value.validate()
    await changePasswordApi(passwordForm)
    ElMessage.success('密码修改成功')
    resetPasswordForm()
  } catch (error: unknown) {
    const errorMessage = (error as { response?: { data?: { message?: string } }; message?: string })?.response?.data?.message || 
                        (error as { message?: string })?.message || 
                        '密码修改失败'
    ElMessage.error(errorMessage)
  } finally {
    changingPassword.value = false
  }
}

// 重置密码表单
const resetPasswordForm = () => {
  Object.assign(passwordForm, {
    oldPassword: '',
    newPassword: '',
    confirmPassword: ''
  })
  passwordFormRef.value?.clearValidate()
}

// 头像上传
const handleAvatarUpload = async (file: File) => {
  // 检查文件类型
  const isImage = file.type.startsWith('image/')
  if (!isImage) {
    ElMessage.error('只能上传图片文件!')
    return false
  }

  // 检查文件大小 (2MB)
  const isLt2M = file.size / 1024 / 1024 < 2
  if (!isLt2M) {
    ElMessage.error('图片大小不能超过 2MB!')
    return false
  }

  try {
    const response = await uploadAvatarApi(file)
    userInfo.value.avatar = response.url
    ElMessage.success('头像上传成功')
  } catch (error) {
    ElMessage.error('头像上传失败')
  }
  
  return false // 阻止自动上传
}

// 格式化日期
const formatDate = (date: string) => {
  if (!date) return '从未登录'
  return new Date(date).toLocaleString('zh-CN', {
    year: 'numeric',
    month: '2-digit',
    day: '2-digit',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit'
  })
}


// 计算密码更新天数
const getDaysSinceUpdate = () => {
  const updateTime = new Date(securityInfo.value.passwordUpdateTime)
  const now = new Date()
  const diffTime = Math.abs(now.getTime() - updateTime.getTime())
  const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
  return diffDays
}

// 获取唯一登录地点数量
const getUniqueLocations = () => {
  const locations = loginLogs.value.map(log => log.location)
  return new Set(locations).size
}

// 计算距上次登录天数
const getLastLoginDays = () => {
  if (loginLogs.value.length === 0) return 0
  const lastLogin = new Date(loginLogs.value[0].loginTime)
  const now = new Date()
  const diffTime = Math.abs(now.getTime() - lastLogin.getTime())
  const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24))
  return diffDays
}

onMounted(() => {
  // 初始化用户信息
  if (userStore.userInfo) {
    Object.assign(userInfo.value, userStore.userInfo)
  }
})
</script>

<style lang="scss" scoped>
.profile-page {
  padding: 0;
  background: transparent;
  height: calc(100vh - 60px);
  overflow: hidden;


  // 卡片样式
  .profile-card,
  .detail-card {
    border-radius: 8px;
    border: 1px solidrgb(255, 255, 255);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
    background: #fff;
    transition: all 0.3s ease;
    margin-bottom: 16px;
    height: calc(100vh - 100px);
    display: flex;
    flex-direction: column;
    
    &:hover {
      box-shadow: 0 4px 16px rgba(0, 0, 0, 0.1);
    }
    
    // 确保卡片头部背景与主体一致
    :deep(.el-card__header) {
      background: #fff !important;
      background-color: #fff !important;
      border-bottom: 1px solid #e8e8e8;
      padding: 16px 20px;
    }
    
    // 确保卡片头部内容区域也是白色背景
    :deep(.el-card__header .card-header) {
      background: #fff !important;
      background-color: #fff !important;
    }
    
    :deep(.el-card__body) {
      flex: 1;
      display: flex;
      flex-direction: column;
      padding: 20px;
    }
  }

  // 卡片头部
  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: none;
    padding: 0;
    
    .header-left {
      display: flex;
      align-items: center;
      gap: 8px;
      
      .header-icon {
        font-size: 20px;
        color: #667eea;
      }
      
      .header-title {
        font-size: 18px;
        font-weight: 600;
        color: #2c3e50;
      }
    }
  }

  // 个人信息区域
  .profile-info {
    text-align: center;
    margin-bottom: 24px;
    flex-shrink: 0;
    
    .avatar-section {
      margin-bottom: 24px;
      position: relative;
      
      .avatar-container {
        position: relative;
        display: inline-block;
        
        .user-avatar {
          border: 4px solid #fff;
          box-shadow: 0 4px 20px rgba(0, 0, 0, 0.1);
          transition: all 0.3s ease;
          
          &:hover {
            transform: scale(1.05);
          }
        }
        
        .avatar-overlay {
          position: absolute;
          bottom: 0;
          right: 0;
          background: #667eea;
          border-radius: 50%;
          width: 32px;
          height: 32px;
          display: flex;
          align-items: center;
          justify-content: center;
          cursor: pointer;
          transition: all 0.3s ease;
          
          &:hover {
            background: #5a6fd8;
            transform: scale(1.1);
          }
          
          .upload-icon {
            color: white;
            font-size: 16px;
          }
        }
      }
      
      .upload-tip {
        margin-top: 8px;
        font-size: 12px;
        color: #909399;
      }
    }
    
    .user-details {
      .user-name {
        margin: 0 0 12px;
        font-size: 24px;
        font-weight: 600;
        color: #2c3e50;
      }
      
      .user-badges {
        margin-bottom: 12px;
        
        .role-tag {
          margin: 0 4px 4px 0;
          border-radius: 20px;
          font-weight: 500;
        }
      }
      
      .user-dept {
        margin: 0;
        color: #7f8c8d;
        font-size: 14px;
        display: flex;
        align-items: center;
        justify-content: center;
        gap: 4px;
      }
    }
  }

  // 统计信息
  .profile-stats {
    border-top: 1px solid #e8f4fd;
    padding-top: 20px;
    flex: 1;
    overflow-y: auto;
    
    // 自定义滚动条样式
    &::-webkit-scrollbar {
      width: 4px;
    }
    
    &::-webkit-scrollbar-track {
      background: #f1f1f1;
      border-radius: 2px;
    }
    
    &::-webkit-scrollbar-thumb {
      background: #c1c1c1;
      border-radius: 2px;
      
      &:hover {
        background: #a8a8a8;
      }
    }
    
    .stats-grid {
      display: grid;
      grid-template-columns: 1fr 1fr;
      gap: 16px;
      
      .stat-item {
        display: flex;
        align-items: center;
        gap: 12px;
        padding: 12px;
        background: linear-gradient(135deg, #f8f9ff 0%, #e8f4fd 100%);
        border-radius: 12px;
        transition: all 0.3s ease;
        
        &:hover {
          background: linear-gradient(135deg, #e8f4fd 0%, #d1e7ff 100%);
          transform: translateY(-2px);
        }
        
        .stat-icon {
          width: 40px;
          height: 40px;
          background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
          border-radius: 10px;
          display: flex;
          align-items: center;
          justify-content: center;
          color: white;
          font-size: 18px;
        }
        
        .stat-content {
          flex: 1;
          
          .stat-label {
            display: block;
            color: #7f8c8d;
            font-size: 12px;
            margin-bottom: 4px;
          }
          
          .stat-value {
            display: block;
            color: #2c3e50;
            font-weight: 600;
            font-size: 14px;
          }
        }
      }
    }
  }

  // 标签页样式
  .profile-tabs {
    height: calc(100vh - 200px);
    display: flex;
    flex-direction: column;
    
    :deep(.el-tabs__header) {
      margin-bottom: 0;
      border-bottom: 1px solid #e8e8e8;
      flex-shrink: 0;
      position: relative;
      
      .el-tabs__nav-wrap {
        background: transparent;
        border-radius: 0;
        padding: 0;
        position: relative;
        
        &::after {
          display: none;
        }
        
        &::before {
          content: '';
          position: absolute;
          bottom: 0;
          left: 0;
          right: 0;
          height: 1px;
          background: #e8e8e8;
          z-index: 0;
        }
      }
      
      .el-tabs__nav {
        display: flex;
        align-items: center;
        width: 100%;
        justify-content: space-between;
        
        .el-tabs__item {
          border-radius: 0;
          font-weight: 500;
          font-size: 16px;
          padding: 0 20px;
          height: 48px;
          line-height: 48px;
          border: none;
          position: relative;
          transition: all 0.3s ease;
          color: #666;
          margin-right: 0;
          display: flex;
          align-items: center;
          justify-content: center;
          min-width: auto;
          flex: 1;
          text-align: center;
          background: transparent !important;
          
          &:hover {
            color: #667eea;
            background: transparent !important;
          }
          
          &.is-active {
            color: #667eea;
            background: transparent !important;
            font-weight: 600;
            position: relative;
            
            &::after {
              content: '';
              position: absolute;
              bottom: -1px;
              left: 0;
              right: 0;
              height: 3px;
              background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
              border-radius: 2px 2px 0 0;
              z-index: 2;
            }
          }
          
          &:first-child {
            padding-left: 0;
            margin-left: 0;
          }
          
          &:last-child {
            padding-right: 0;
            margin-right: 0;
          }
          
          // 确保所有标签页的选中状态完全一致
          &.is-active,
          &.is-active:hover {
            color: #667eea;
            background: transparent !important;
            font-weight: 600;
          }
          
          // 确保悬停状态不影响选中状态
          &:hover:not(.is-active) {
            color: #667eea;
            background: transparent !important;
            font-weight: 500;
          }
        }
      }
    }
    
    :deep(.el-tabs__content) {
      flex: 1;
      overflow-y: auto;
      padding: 0;
    }
  }

  // 标签页内容
  .tab-content {
    padding: 24px 0;
    height: 100%;
    overflow-y: auto;
    
    // 自定义滚动条样式
    &::-webkit-scrollbar {
      width: 6px;
    }
    
    &::-webkit-scrollbar-track {
      background: #f1f1f1;
      border-radius: 3px;
    }
    
    &::-webkit-scrollbar-thumb {
      background: #c1c1c1;
      border-radius: 3px;
      
      &:hover {
        background: #a8a8a8;
      }
    }
    
    .form-section {
      margin-bottom: 32px;
      
      .section-title {
        font-size: 18px;
        font-weight: 600;
        color: #2c3e50;
        margin: 0 0 16px;
        padding-bottom: 8px;
        border-bottom: 1px solid #e8e8e8;
        position: relative;
        
        &::after {
          content: '';
          position: absolute;
          bottom: -1px;
          left: 0;
          width: 70px;
          height: 2px;
          background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
          border-radius: 1px;
        }
      }
      
      .section-desc {
        color: #7f8c8d;
        font-size: 14px;
        margin: 0 0 20px;
        line-height: 1.5;
      }
    }
  }

  // 表单样式
  .profile-form,
  .password-form {
    max-width: 100%;
    
    :deep(.el-form-item) {
      margin-bottom: 24px;
      
      .el-form-item__label {
        font-weight: 500;
        color: #2c3e50;
        font-size: 14px;
        line-height: 1.5;
      }
      
      .el-input {
        .el-input__wrapper {
          border-radius: 6px;
          border: 1px solid #d9d9d9;
          transition: all 0.3s ease;
          box-shadow: none;
          
          &:hover {
            border-color: #667eea;
            box-shadow: 0 0 0 1px rgba(102, 126, 234, 0.1);
          }
          
          &.is-focus {
            border-color: #667eea;
            box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
          }
        }
        
        .el-input__prefix {
          color: #999;
        }
      }
      
      .el-select {
        .el-input__wrapper {
          border-radius: 6px;
          border: 1px solid #d9d9d9;
          transition: all 0.3s ease;
          
          &:hover {
            border-color: #667eea;
            box-shadow: 0 0 0 1px rgba(102, 126, 234, 0.1);
          }
          
          &.is-focus {
            border-color: #667eea;
            box-shadow: 0 0 0 2px rgba(102, 126, 234, 0.1);
          }
        }
      }
    }
  }

  // 密码操作按钮
  .password-actions {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 12px;
    width: 100%;
    
    .el-button {
      border-radius: 6px;
      font-weight: 500;
      padding: 10px 20px;
      min-width: 100px;
    }
  }

  // 角色标签
  .role-tags {
    .role-tag-large {
      margin: 0 8px 8px 0;
      border-radius: 20px;
      font-weight: 500;
      padding: 8px 16px;
    }
  }


  // 表单操作按钮
  .form-actions {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid #e8e8e8;
    text-align: center;
    
    .el-button {
      border-radius: 6px;
      font-weight: 500;
      padding: 10px 20px;
      margin-right: 12px;
      font-size: 14px;
      height: 36px;
      
      &.el-button--primary {
        background: #667eea;
        border-color: #667eea;
        
        &:hover {
          background: #5a6fd8;
          border-color: #5a6fd8;
        }
        
        &:focus {
          background: #5a6fd8;
          border-color: #5a6fd8;
        }
      }
      
      &:not(.el-button--primary) {
        color: #666;
        border-color: #d9d9d9;
        
        &:hover {
          color: #667eea;
          border-color: #667eea;
        }
      }
    }
  }

  // 登录日志表格
  .login-logs-table {
    border-radius: 12px;
    overflow: hidden;
    width: 100%;
    
    :deep(.el-table__header) {
      background: #f8f9fa;
      
      th {
        background: #f8f9fa;
        color: #2c3e50;
        font-weight: 600;
        border: none;
        padding: 12px 8px;
        font-size: 14px;
      }
    }
    
    :deep(.el-table__body) {
      tr {
        transition: all 0.3s ease;
        
        &:hover {
          background: #f8f9ff;
        }
      }
      
      td {
        border: none;
        padding: 12px 8px;
        vertical-align: middle;
      }
    }
    
    .time-cell,
    .ip-cell,
    .location-cell {
      display: flex;
      align-items: center;
      gap: 8px;
      font-size: 13px;
      min-height: 24px;
      
      .el-icon {
        color: #667eea;
        font-size: 14px;
        flex-shrink: 0;
      }
      
      .cell-text {
        flex: 1;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
      }
    }
    
    .browser-tag,
    .os-tag,
    .status-tag {
      margin: 0;
      font-size: 12px;
      padding: 4px 8px;
      border-radius: 4px;
      font-weight: 500;
      
      .el-icon {
        margin-right: 4px;
        font-size: 12px;
      }
    }
    
    .browser-tag {
      background: #e3f2fd;
      color: #1976d2;
      border: 1px solid #bbdefb;
    }
    
    .os-tag {
      background: #fff3e0;
      color: #f57c00;
      border: 1px solid #ffcc02;
    }
    
    .status-tag {
      &.el-tag--success {
        background: #e8f5e8;
        color: #2e7d32;
        border: 1px solid #c8e6c9;
      }
      
      &.el-tag--danger {
        background: #ffebee;
        color: #c62828;
        border: 1px solid #ffcdd2;
      }
    }
  }

  // 基本信息区域
  .basic-info-section {
    background: linear-gradient(135deg, #f0f9ff 0%, #e0f2fe 100%);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid #bae6fd;
    margin-bottom: 24px;
    
    .section-title {
      color: #0369a1;
      font-size: 18px;
      font-weight: 600;
      margin: 0 0 20px 0;
      display: flex;
      align-items: center;
      gap: 8px;
      
      &::before {
        content: '';
        width: 4px;
        height: 20px;
        background: linear-gradient(135deg, #0ea5e9 0%, #0284c7 100%);
        border-radius: 2px;
      }
    }
  }

  // 组织信息区域
  .organization-info-section {
    background: linear-gradient(135deg, #f0fdf4 0%, #dcfce7 100%);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid #bbf7d0;
    margin-bottom: 24px;
    
    .section-title {
      color: #166534;
      font-size: 18px;
      font-weight: 600;
      margin: 0 0 20px 0;
      display: flex;
      align-items: center;
      gap: 8px;
      
      &::before {
        content: '';
        width: 4px;
        height: 20px;
        background: linear-gradient(135deg, #22c55e 0%, #16a34a 100%);
        border-radius: 2px;
      }
    }
  }

  // 安全设置区域
  .security-section {
    background: linear-gradient(135deg, #fff5f5 0%, #fef7f7 100%);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid #fed7d7;
    
    .section-title {
      color: #dc2626;
      font-size: 18px;
      font-weight: 600;
      margin: 0 0 20px 0;
      display: flex;
      align-items: center;
      gap: 8px;
      
      &::before {
        content: '';
        width: 4px;
        height: 20px;
        background: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
        border-radius: 2px;
      }
    }
    
    // 确保密码表单中的按钮居中
    .password-form {
      :deep(.el-form-item) {
        &:last-child {
          .el-form-item__content {
            display: flex;
            justify-content: center;
            width: 100%;
          }
        }
      }
    }
    
    .security-status {
      margin-bottom: 32px;
      
      .security-item {
        display: flex;
        justify-content: space-between;
        align-items: center;
        padding: 16px 0;
        border-bottom: 1px solid #f0f0f0;
        
        &:last-child {
          border-bottom: none;
        }
        
        .security-label {
          display: flex;
          align-items: center;
          gap: 8px;
          font-weight: 500;
          color: #2c3e50;
          min-width: 120px;
          
          .el-icon {
            color: #667eea;
            font-size: 16px;
          }
        }
        
        .security-value {
          display: flex;
          flex-direction: column;
          align-items: flex-end;
          gap: 4px;
          
          .security-text {
            font-weight: 500;
            color: #2c3e50;
          }
          
          .security-desc {
            font-size: 12px;
            color: #999;
          }
        }
      }
    }
  }

  // 登录记录区域
  .login-logs-section {
    background: linear-gradient(135deg, #faf5ff 0%, #f3e8ff 100%);
    padding: 24px;
    border-radius: 12px;
    border: 1px solid #d8b4fe;
    
    .section-title {
      color: #7c3aed;
      font-size: 18px;
      font-weight: 600;
      margin: 0 0 20px 0;
      display: flex;
      align-items: center;
      gap: 8px;
      
      &::before {
        content: '';
        width: 4px;
        height: 20px;
        background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
        border-radius: 2px;
      }
    }
    
    .section-desc {
      color: #6b21a8;
      font-size: 14px;
      margin: 0 0 24px 0;
      line-height: 1.5;
    }
    
    .login-stats {
      display: grid;
      grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
      gap: 16px;
      margin-bottom: 24px;
      
      .stat-card {
        background: rgba(255, 255, 255, 0.8);
        border-radius: 8px;
        padding: 16px;
        display: flex;
        align-items: center;
        gap: 12px;
        transition: all 0.3s ease;
        
        &:hover {
          background: rgba(255, 255, 255, 0.9);
          transform: translateY(-2px);
          box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        
        .stat-icon {
          width: 40px;
          height: 40px;
          background: linear-gradient(135deg, #a855f7 0%, #7c3aed 100%);
          border-radius: 8px;
          display: flex;
          align-items: center;
          justify-content: center;
          color: white;
          font-size: 18px;
        }
        
        .stat-content {
          .stat-number {
            font-size: 20px;
            font-weight: 600;
            color: #2c3e50;
            line-height: 1;
            margin-bottom: 4px;
          }
          
          .stat-label {
            font-size: 12px;
            color: #7f8c8d;
            line-height: 1;
          }
        }
      }
    }
  }

  // 响应式设计
  @media (max-width: 1200px) {
    .el-row {
      .el-col {
        &:first-child {
          margin-bottom: 16px;
        }
      }
    }
  }

  @media (max-width: 768px) {
    .page-header {
      .page-title {
        font-size: 20px;
      }
      
      .page-subtitle {
        font-size: 13px;
      }
    }
    
    .profile-info {
      .user-details {
        .user-name {
          font-size: 20px;
        }
      }
    }
    
    .stats-grid {
      grid-template-columns: 1fr;
    }
    
    .form-actions {
      .el-button {
        width: 100%;
        margin: 8px 0;
      }
    }
    
    .profile-tabs {
      :deep(.el-tabs__header) {
        .el-tabs__nav {
          .el-tabs__item {
            padding: 0 16px;
            font-size: 14px;
            height: 44px;
            line-height: 44px;
          }
        }
      }
    }
    
    // 移动端表格优化
    .login-logs-table {
      :deep(.el-table__header) {
        th {
          padding: 8px 4px;
          font-size: 12px;
        }
      }
      
      :deep(.el-table__body) {
        td {
          padding: 8px 4px;
        }
      }
      
      .time-cell,
      .ip-cell,
      .location-cell {
        gap: 4px;
        font-size: 12px;
        
        .el-icon {
          font-size: 12px;
        }
      }
      
      .browser-tag,
      .os-tag,
      .status-tag {
        font-size: 11px;
        padding: 2px 6px;
      }
    }
  }

  @media (max-width: 480px) {
    .page-header {
      .page-title {
        font-size: 18px;
      }
    }
    
    .profile-info {
      .avatar-section {
        .avatar-container {
          .user-avatar {
            width: 80px;
            height: 80px;
          }
          
          .avatar-overlay {
            width: 28px;
            height: 28px;
            
            .upload-icon {
              font-size: 14px;
            }
          }
        }
      }
    }
    
    .profile-form,
    .password-form {
      :deep(.el-form-item) {
        .el-form-item__label {
          font-size: 14px;
        }
      }
    }
  }
}
</style>
